package com.talkweb.securitycamera.data.hadoopFile;

import com.talkweb.securitycamera.common.constans.FileType;

import java.util.HashMap;
import java.util.Map;

public class PolicyFactory {

    private static class PolicyFactoryHolder {
        public static PolicyFactory instance = new PolicyFactory();
    }

    private PolicyFactory() {
        registeMemoryPolicy(FileType.FILE_TYPE_IMAGE, new SimpleImageMemoryPolicy());
        registeMemoryPolicy(FileType.FILE_TYPE_VIDEO, new SimpleVideoMemoryPolicy());
    }

    /**
     * 策略缓存
     */
    private Map<Integer, IMemoryPolicy> policyMap = new HashMap();

    public static PolicyFactory getInstance() {
        return PolicyFactoryHolder.instance;
    }


    public IMemoryPolicy getMemoryPolicy(FileType type, IMemoryPolicy policy) {
        return policyMap.get(type.getValue());
    }

    public void registeMemoryPolicy(FileType type, IMemoryPolicy policy) {
        policyMap.put(type.getValue(), policy);
    }

}
